import { Request, Response, NextFunction } from 'express';

export const responseEnhancer = (req: Request, res: Response, next: NextFunction) => {
  res.safeJson = (data: any, message = 'OK', code = 0, status = 200) => {
    const safe = JSON.parse(JSON.stringify(data, (_, v) =>
      typeof v === 'bigint' ? v.toString() : v
    ));
    res.status(status).json({ code, message, data: safe });
  };
  next();
};
